package com.example.demo.testTwo;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @description 循环依赖
 *
 * @author lilinchun
 * @date 2024/03/20
 */
public class TestTwo {


    public static void main(String[] args) {
        List<String> list = Arrays.asList("测试1", "测试2");
        String a = test(list, "测试");
        System.out.println(a);
//        Integer newA = null;
//        testNew(list, 1, 0, newA);
//        System.out.println("---------" + newA);

    }

    private static String test(List<String> list, String a) {
        int count = 0;
        boolean flag = true;
        String newA = a;
        while (flag) {
            flag = list.contains(newA);
            count = count + 1;
            newA = a + count;
            System.out.println(newA);
        }
        count = count - 1;
        a = 0 == count ? a : a + count;
        return a;
    }


    private static void testNew(List<Integer> list, Integer a, Integer count, Integer newA) {
        Integer num = 0 == count ? a : a + count;
        if (list.contains(num)) {
            count = count + 1;
            testNew(list, a, count, newA);
        }
        newA = num;
    }
}
